package io.renren.modules.recorderReport.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.renren.modules.recorderReport.model.ReportFinanceAuditExcelBean;
import io.renren.modules.recorderReport.model.ReportFinanceAuditExportExcel;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.recorderReport.entity.ReportInfoEntity;
import io.renren.modules.recorderReport.service.ReportInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 
 * 
 * @author wxy
 * @email sharonwang_xy@163.com
 * @date 2018-11-07 16:03:18
 */
@RestController
@RequestMapping("recorderReport/reportinfo")
public class ReportInfoController {
	@Autowired
	private ReportInfoService reportInfoService;
	
	/**
	 * 上报信息列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("recorderReport:reportinfo:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<ReportInfoEntity> reportInfoList = reportInfoService.queryList(query);
		int total = reportInfoService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(reportInfoList, total, query.getLimit(), query.getCurrPage());
		
		return R.ok().put("page", pageUtil);
	}

	/**
	 * 财务审核信息列表
	 */
	@RequestMapping("/listReportFinanceAuditInfo")
	@RequiresPermissions("recorderReport:reportinfo:listReportFinanceAuditInfo")
	public R listReportFinanceAuditInfo(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);

		List<ReportInfoEntity> reportInfoList = reportInfoService.queryListReportFinanceAuditInfo(query);
		int total = reportInfoService.queryTotalReportFinanceAuditInfoNum(query);

		PageUtils pageUtil = new PageUtils(reportInfoList, total, query.getLimit(), query.getCurrPage());

		return R.ok().put("page", pageUtil);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("recorderReport:reportinfo:info")
	public R info(@PathVariable("id") String id){
		ReportInfoEntity reportInfo = reportInfoService.queryObject(id);
		
		return R.ok().put("reportInfo", reportInfo);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("recorderReport:reportinfo:save")
	public R save(@RequestBody ReportInfoEntity reportInfo){
		reportInfoService.save(reportInfo);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("recorderReport:reportinfo:update")
	public R update(@RequestBody ReportInfoEntity reportInfo){
		reportInfoService.update(reportInfo);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("recorderReport:reportinfo:delete")
	public R delete(@RequestBody String[] ids){
		reportInfoService.deleteBatch(ids);
		
		return R.ok();
	}


	/**
	 * 审核
	 */
	@RequestMapping("/reportFinanceAudit/{id}")
	@RequiresPermissions("recorderReport:reportinfo:reportFinanceAudit")
	public R reportFinanceAudit(@PathVariable("id") String id){

		ReportInfoEntity reportInfo = reportInfoService.queryObject(id);
		reportInfo.setState("5");
		reportInfoService.update(reportInfo);
		return R.ok();
	}

	/**
	 * 导出列表
	 */
	@RequestMapping("/exportReportFinanceAudit")
	public void exportReportFinanceAudit(@RequestParam Map<String, Object> params , HttpServletRequest request, HttpServletResponse response){

        Query query = new Query(params);

        List<ReportFinanceAuditExcelBean> list = new ArrayList<>();
        list= reportInfoService.listReportFinanceAuditExcel(query);


            //设置excel列名及宽度
            ReportFinanceAuditExportExcel<ReportFinanceAuditExcelBean> ex = new ReportFinanceAuditExportExcel<>();
            String[] headers = { "姓名", "身份证号","联系方式","银行卡号","上报时间","上报地点","违法车牌","违法地点","行驶方向","行驶车道","违法类型","违法代码","车辆品牌","车辆类型","车辆颜色","车辆型号","状态"};
            int[] columnWidths ={4000,   6000,    5000,    6000,     5000,     8000,    5000,     5000,    5000,     5000,    5000,   5000,    5000,     5000,    5000,    5000,    5000};

            //导出excel
            ex.exportExcel("举报举证信息列表", headers, columnWidths, list, response);

    }


}
